<!-- 已完成的申请 -->
<template>
  <div>
    <div class="searchbox">
      <el-form :inline="true" size="small" label-width="100px">
        <jt-easy-collapse :has-expand="true">
          <template slot="expand">
          <el-form-item label="任务单号">
            <el-input size="small" v-model="form.taskNo" placeholder="任务单号"></el-input>
          </el-form-item>
          <el-form-item label="零件号">
            <el-input size="small" v-model="form.partNumber" placeholder="零件号"></el-input>
          </el-form-item>
          <el-form-item label="零件名称">
            <el-input size="small" v-model="form.partName" placeholder="零件名称"></el-input>
          </el-form-item>
          <el-form-item label="完成日期:">
            <el-date-picker size="small" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" v-model="form.date" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              style="width: 220px">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="热处理炉号">
            <el-input size="small" v-model="form.heatingNumber" placeholder="热处理炉号"></el-input>
          </el-form-item>
          <el-form-item label="零件图号">
            <el-input size="small" v-model="form.partGraphNumber" placeholder="零件图号"></el-input>
          </el-form-item>
          <el-form-item style="margin-left: 20px;">
            <el-button size="mini" type="primary" @click="showList">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button size="mini" @click='clearForm'>清除</el-button>
          </el-form-item>
</template>
        </jt-easy-collapse>
      </el-form>
    </div>
    <div class="contentbox">
        <div style="float: left;padding-left: 20px;font-size: 15px;color: #666;padding-top: 6px;">
          已完成的申请 共 <span style="color: red;">{{pageTotal}}</span> 条数据
        </div>
        <el-row style="float: right;margin-right: 20px;margin-bottom: 15px;" type="flex" justify="end">
          <el-col>
            <jt-table-column-filter tableName='acompletedApplication' :table-key.sync="tableKey" :header-data.sync="tableHeaderArr" :filter-column.sync="filterColumnData"></jt-table-column-filter>
          </el-col>
        </el-row>
        <!-- 表格 -->
        <el-table :data="tableData" :key='tableKey' v-loading="loading" stripe>
          <el-table-column :index="indexMethod" type="index" label="序号" width="50" align="center" :resizable="false"></el-table-column>
          <el-table-column align="center" :key='item' v-for='item in filterColumnData' :resizable="false"
              :label="getTableHeaderLabel(item)"
              :prop="item"
              :min-width="getTableColumnWidth(item)"
              :fixed="getTableColumnFixed(item)"
              :sortable="getTableColumnSort(item)">
<template slot-scope="scope">
   {{scope.row[item]}}
</template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="center">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="pageSizeArr"
            :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageTotal"></el-pagination>
        </el-row>
    </div>
  </div>
</template>

<script>
  import JtTableColumnFilter from 'components/jt-table-column-filter/index'; // 导入表格列筛选组件
  import {
    getCompleteApply
  } from 'service/task';
  import JtEasyCollapse from "components/jt-easy-collapse/index";
  import {
    APPLY_TYPE_LIST,
    APPLY_STATUS_LIST
  } from 'service/constant';
  export default {
    name: 'CompleteApplication',
    components: {
      'jt-table-column-filter': JtTableColumnFilter,
      "jt-easy-collapse": JtEasyCollapse,
    },
    data() {
      return {
        tableKey: 1, // table key
        filterColumnData: [],
        tableHeaderArr: [{
            'name': 'taskAuditTime',
            'alias': '完成日期',
            'default': true,
            'width': 110,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'taskNo',
            'alias': '任务单号',
            'default': true,
            'width': 170,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'partNumber',
            'alias': '零件号',
            'default': true,
            'width': 80,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'partName',
            'alias': '零件名称',
            'default': true,
            'width': 80,
            'fixed': false,
            'sort': true
          },
          {
            'name': 'heatingNumber',
            'alias': '热处理炉号',
            'default': true,
            'width': 80,
            'fixed': false,
            'sort': true
          }
        ],
        tableData: [],
        loading: false,
        form: {
          taskNo: '',
          partNumber: '',
          heatingNumber: '',
          date: '',
          partName: '',
          partGraphNumber: ''
        },
        currentPage: 1,
        pageSizeArr: [10, 20, 50, 100],
        pageSize: 10,
        pageTotal: 10
      }
    },
    mounted() {
      this.showList();
    },
    methods: {
      indexMethod(index) {
        return index + this.pageSize * (this.currentPage-1) + 1;
      },
      clearForm() {
        this.form = {};
        this.showList();
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.showList();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.showList();
      },
      // 表格数据展示
      showList() {
        let startDate = '';
        let endDate = '';

        if (this.form.date && this.form.date != '') {
          startDate = this.form.date[0];
          endDate = this.form.date[1];
        }
        this.loading = true;
        // this.axios.get('/task/applyList')
        getCompleteApply(this.form.taskNo, this.form.partNumber, this.form.heatingNumber, startDate, endDate, this.form.partName, this.form.partGraphNumber, this.form.taskStatus, this.currentPage, this.pageSize, '', '')
          .then(res => {
            // console.log(res)
            this.tableData = res.data.result.content;
            // this.currentPage = res.data.result.pageable.pageNumber;
            this.pageSize = res.data.result.pageable.pageSize;
            this.pageTotal = res.data.result.totalElements;
            this.loading = false;
          })
      },
      // 表头展示
      getTableHeaderLabel(str) {
        return this.getTableSomeValue(str, 'alias');
      },
      // 获取表格列的宽度
      getTableColumnWidth(str) {
        return this.getTableSomeValue(str, 'width');
      },
      // 获取表格列是否是固定的
      getTableColumnFixed(str) {
        return this.getTableSomeValue(str, 'fixed');
      },
      // 获取表格列是否排序
      getTableColumnSort(str) {
        return this.getTableSomeValue(str, 'sort');
      },
      // 获取表格表头，列宽度，列固定，列排序的值
      getTableSomeValue(str, keyName) {
        for (var value of this.tableHeaderArr) {
          if (value['name'] == str) {
            return value[keyName];
          }
        }
      }
    }
  }
</script>


